package com.tz.actions;

import com.opensymphony.xwork2.ActionSupport;
import com.tz.entity.Category;
import com.tz.service.CategoryService;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/**
 * Created by Administrator on 2016/8/4.
 */
@Namespace(value = "/category")
@ParentPackage("json-default")
public class CategoryAction extends ActionSupport{

    private List<Category> categories;

    @Autowired
    private CategoryService categoryService;

    @Action(value = "list",results = {
            @Result(type = "json",params = {"root","categories"})
    })
    public String list(){
        categories = categoryService.findAllCategory();
        return SUCCESS;
    }

    public List<Category> getCategories() {
        return categories;
    }

    public void setCategories(List<Category> categories) {
        this.categories = categories;
    }
}
